/**
	Constructs a 

	@author Matthew Richmond
	@version 2006-05-02

	@usage

	- Activate with:
	<code>

	</code>

*/
import timber.ui.LayoutElement;

class timber.ui.LayoutController extends LayoutElement {

// ===========================================================
// - CONSTRUCTOR
// ===========================================================

	private var bg:MovieClip;
	private var childObject:Array;
	private var childCount:Number;
	
	private var innerHeight:Number;
	private var innerWidth:Number;

	private var isScale9Grid:Boolean = false;
	
	private var padLeft:Number;
	private var padRight:Number;

	function LayoutController (obj:Object, hA:String, vA:String, hR:String, vR:String, uS:Boolean) {
		super (obj, hA, vA, hR, vR, uS);
		//trace("---- LayoutController: for "+obj._name);
		
		if (obj.bg_mc) {
			trace("LayoutController: ERROR!");
		}
		
		if (obj.bg_mc != undefined) {
			//trace("found bg_mc");
			bg = obj.bg_mc;
			//this.obj = obj.bg_mc;
		}
		
		// make new array
		childObject = new Array();
		
		calcInnerWidth ();
		calcInnerHeight ();
	};
	
	function addChild (obj:Object, hA:String, vA:String, hR:String, vR:String, uS:Boolean){
		//trace("setChild");
		
		var child:LayoutElement = new LayoutElement(obj, hA, vA, hR, vR, false);
		childObject.push(child);
		childCount = childObject.length;
	};
	
	
	function update (){
		super.update();
		//trace(obj._name+" update");
		for ( var i=0; i<childCount; i++ ) {
			childObject[i].update();
		};
	};
	
	
	// ===========================================================
	// - CALC
	// ===========================================================
	
	/**
	Overwrites the calcInitWidth class in our superclass

	@param	value
	*/
	function calcInitWidth ():Number{
		//trace("calcInitWidth: for "+obj._name+" is: "+obj.bg_mc._width);
		
		var val:Number;
		
		if (isScale9Grid) {
			//isScale9Grid		
			val = obj.bg_mc.scale9Grid.width;
		} else {
			val = obj.bg_mc._width;
		}

		//trace("calcInitWidth is: "+val);
		return val;
	};

	/**
	Overwrites the calcInitHeight class in our superclass

	@param	value
	*/
	function calcInitHeight ():Number{
		//trace("calcInitHeight: for "+obj._name+" is: "+obj.bg_mc._height);
		
		var val:Number;
		
		if (isScale9Grid) {
			//isScale9Grid		
			val = obj.bg_mc.scale9Grid.height;
		} else {
			val = obj.bg_mc._height;
		}

		//trace("calcInitWidth is: "+val);
		return val;
	};
	
	function calcInnerWidth (){
		//trace("calcInnerWidth");
		
		innerWidth = obj._width - calcInitWidth ();
		//trace("innerWidth is: "+innerWidth);
	};
	
	function calcInnerHeight (){
		//trace("calcInnerHeight");
		
		innerHeight =  obj._height - calcInitHeight ();
		//trace("innerHeight is: "+innerHeight);
	};
	
	// ===========================================================
	// - POSITION
	// ===========================================================
	
	/**
	Overwrites the updateWidth class in our superclass

	@param	value
	*/
	function updateWidth (v:Number){
		//trace(obj._name+" updateWidth to "+v);
		
		if (horizontalResize == "on") v -= innerWidth
		obj.bg_mc._width = v;
	};
	
	/**
	Overwrites the updateHeight class in our superclass

	@param	value
	*/
	function updateHeight (v:Number){
		//trace(obj._name+" updateHeight to "+v);
		
		if (verticalResize == "on") v -= innerHeight
		obj.bg_mc._height = v;
	};
	
};